<html>
	<head>
		<link rel="stylesheet" type="text/css" href="style.css">
		<?php
		function readFiles($dir){
			$handle=opendir ($dir);
			$filesarray = array();

			while ($datei = readdir ($handle)) {
				if(substr($datei,-4) == ".txt")
					$filesarray[] = $datei; //Nimmt erste freie Stelle
			}

			closedir($handle);
			return $filesarray;
		}
		
		function readSubFolder($dir){
			$handle = opendir($dir);
			$subfolder = array();
			
			while($folder = readdir($handle)) {
				if(!is_file($folder) && substr($folder,0,1) != ".")
					$subfolder[] = $folder;
			}
			
			closedir($handle);
			return $subfolder;
			
		}
			
			
			$letter = $_GET["letter"];
			if($letter == null) {
				?>
					<script type="text/javascript">
						window.location = "index.php";
					</script>
				<?php 
			}
			
		?>
	<title><?php echo "Buchstabe: $letter"; ?></title>
	</head>
	<body>
	<?php
		$files = readFiles("./ebooks/" . $letter . "/");
		$authors = array();
		foreach($files as $file){
			$split = explode("-", $file);
			$aname = $split[0];
			if(isset($authors[$aname]))
				$authors[$aname]++;
			else
				$authors[$aname] = 1; 
		}
	?>
		<script type="text/javascript" src="wz_tooltip.js"></script>
		<script type="text/javascript" src="sidebarLetters.js"></script>
		<div id="title">
			EBook-Reader
		</div>
		<div id="bar">
			<div id="sidebarLetters-close">
				<a onclick="javaScript: openLetters()"> ||| </a>
			</div>
			<div id="letterlist" isVisible="false">
				<?php
					echo "<a class='letter' href='index.php'>&nbsp; @ &nbsp;</a>";
					for($i = 1; $i <= 26; $i++){
						echo "<a class='letter";
						if($letter == chr(64 + $i)) echo "Cur";
						echo "' href='makelist.php?letter=";
						echo chr(64 + $i);
						echo "'>&nbsp; ";
						echo chr(64 + $i);
						echo " &nbsp;</a>";
					}
				?>
			</div>
		</div>
		<div id="main">
			<?php
				if(count($files) == 0)
					echo "Keine Autoren zu diesem Buchstaben in Bibliothek vorhanden! ";
				else {
					echo "<table id='alist'>";
					foreach($authors as $author => $count){
						echo "<tr><td><a href='makelistAuthor.php?letter=$letter&author=$author'>$author</a></td><td align='right'>$count</td></tr>";
					}
					echo "</table>";
				}
			?>
		</div>
	</body>
</html>